<?php

/**
 * @file
 * 
 * @package    Europa
 * @subpackage View
 */

/**
 * @class
 * 
 * @name Europa_View_Json
 * @desc Renders the current view content as JSON. Support jsonp (wrapping it into a callback function,
 * function parameter is given in config under jsonp)
 */
class Europa_View_Json extends Europa_View 
{
	protected $_config = array('jsoncallback' => 'callback');
	
	/**
	 * @method
	 * @magic
	 * 
	 * @name __toString
	 * @desc Returns the JSON content of the rendered view.
	 * 
	 * @return String
	 */
	public function __toString()
	{
		$callback = $this->getConfig('jsoncallback');
		$jsonstr = json_encode($this->_content);
		if($_GET[$callback])
			return $_GET[$callback] . '(' . $jsonstr . ')';

		return $jsonstr; 
	}
	
	/**
	 * @method
	 * @public
	 * 
	 * @name render
	 * @desc Sets the script to be rendered.
	 * 
	 * @param String $script - The path to the script to be rendered relative to the view path, excluding the extension.
	 * 
	 * @return Object Europa_View
	 */
	public function render($script)
	{
		return $this;
	}
}
